import pytest
from common.request_util_test import RequestUtil
from common.test_yaml_util_test import YamlUtil

class TestAppstore:
    @pytest.mark.parametrize('yaml', YamlUtil().read_testcase_yaml('v24.06/appStore/GET_get_chart_all_version.yaml'))
    def test_get_chart_all_version(self, yaml, get_env_info):
        # 查询指定Chart（所有版本）
        baseUrl = get_env_info
        url = baseUrl +yaml['request']['url']
        method = yaml['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == yaml['validate'][0]['equals']['status_code']

    @pytest.mark.parametrize('yaml', YamlUtil().read_testcase_yaml('v24.06/appStore/GET_get_chart_specified_version.yaml'))
    def test_get_chart_specified_version(self, yaml, get_env_info):
        # 查询指定Chart（指定版本）
        baseUrl = get_env_info
        url = baseUrl +yaml['request']['url']
        method = yaml['request']['method']
        req = RequestUtil().send_request(method, url)
        # print(req.content)
        assert req.status_code ==yaml['validate'][0]['equals']['status_code']

    @pytest.mark.parametrize('yaml', YamlUtil().read_testcase_yaml('v24.06/appStore/GET_get_chart_files.yaml'))
    def test_get_chart_files(self, yaml, get_env_info):
        # 查询Chart文件
        baseUrl = get_env_info
        url = baseUrl +yaml['request']['url']
        method = yaml['request']['method']
        req = RequestUtil().send_request(method, url)
        # print(req.content)
        assert req.status_code == yaml['validate'][0]['equals']['status_code']

    @pytest.mark.parametrize('yaml', YamlUtil().read_testcase_yaml('v24.06/appStore/POST_helm_install.yaml'))
    def test_helm_install(self, yaml, get_env_info):
        # 安装Helm Release
        baseUrl = get_env_info
        method =yaml['request']['method']
        url = baseUrl +yaml['request']['url']
        headers = yaml['request']['headers']
        data =yaml['request']['data']
        req = RequestUtil().send_request(method, url, headers=headers, json=data)
        assert req.status_code == yaml['validate'][0]['equals']['status_code']